//
//  ByViewPhysicalBuySegment.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/13.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByViewPhysicalBuySegment.h"

@implementation ByViewPhysicalBuySegment
{
    NSInteger _preTag;
}
- (instancetype)init{
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    NSArray *titles = @[@"固定体检套餐",@"自选体检套餐"];
    UIButton *fixedButton = [[UIButton alloc] init];
    [self addSubview:fixedButton];
    [fixedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(0));
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH / 2, 30));
    }];
    [fixedButton setTitle:titles[0] forState:UIControlStateNormal];
    [fixedButton setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
    fixedButton.titleLabel.font = FONT(14);
    fixedButton.tag = 10;
    _preTag = 10;

    UIButton *optionalButton = [[UIButton alloc] init];
    [self addSubview:optionalButton];
    [optionalButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(fixedButton.mas_right);
        make.top.equalTo(@(5));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH / 2, 30));
    }];
    [optionalButton setTitle:titles[1] forState:UIControlStateNormal];
    [optionalButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
     optionalButton.titleLabel.font = FONT(14);
    optionalButton.tag = 11;
    [fixedButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [optionalButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction:(UIButton *)button{
    if (button.tag == _preTag) {
        return;
    }
    UIButton *preButton = [self viewWithTag:_preTag];
    [preButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
    _preTag = button.tag;
    if (self.selectBlock) {
        self.selectBlock(button.tag - 10);
    }
}

@end
